package com.sh_rw.label;

/**
 * Created by rw-duke on 2018/4/4.
 */

public class CheckUtils {

    /**
     * 检查数据是否合格
     *
     * @param bytes
     * @return  true：合格，false：不合格
     */
    public static boolean checkPacket(byte[] bytes) {
        if (bytes == null) {
            return false;
        }
        int length = bytes.length;

        if ((bytes[0] & 0xff) == 2 && (bytes[1] & 0xff) == (byte) 3
                && (bytes[2] & 0xff) == (byte) 4
                && (bytes[3] & 0xff) == (byte) 5) {

            int len = (bytes[4] & 0xff) * 256 + (bytes[5] & 0xff);
            if (len == length) {
                return true;
            }
        }

        return false;
    }
}
